extends Node2D
@export var health_component: Node
@export var sprite: Sprite2D

func _ready() -> void:
	$GPUParticles2D.texture = sprite.texture
	health_component.died.connect(on_died)
	
	
func on_died():
	# 死亡效果其实是增加了一个动画在节点中

	if owner ==null || not owner is Node2D:
		return 
	var spawn_position = owner.global_position
	var entities  = get_tree().get_first_node_in_group("enemy")
	get_parent().remove_child(self)
	entities.add_child(self) # 增加死亡动画
	global_position = spawn_position
	$AnimationPlayer.play("defaulkt")
